'use strict';

app.controller('viewLandRecordCtrl', function($element, $scope, $state, rest, user, $rootScope, ngDialog, uiLoad, $timeout, $window) {
    var data = angular.copy($scope.ngDialogData, {});
    $scope.landlordId1 = data.landlordId;

    // 认领状态
    var claimList = {
            "RETURNBACK": {
                text: "回退补件",
                next: "回退"
            },
            "UNCHECK": {
                text: "房东待审核",
                next: "待审核"
            },
            "CHECKSUCCESS": {
                text: "房东审核通过",
                next: "通过"
            },
            "INREVIEW": {
                text: "审核中",
                next: "认领"
            },
            "CHECKFAILE": {
                text: "房东审核未通过",
                next: "拒绝"
            }
        }
        // 目标状态
    var _mlist = {
        "RETURNBACK": {
            text: "回退补件",
            next: "回退补件"
        },
        "UNCHECK": {
            text: "房东待审核",
            next: "审核中"
        },
        "CHECKSUCCESS": {
            text: "房东审核通过",
            next: "审核通过"
        },
        "INREVIEW": {
            text: "审核中",
            next: "审核中"
        },
        "CHECKFAILE": {
            text: "房东审核未通过",
            next: "审核拒绝"
        }
    }

    var token = $window.localStorage.getItem("token");

    $scope.queryParams = {
        landlordId: data.landlordId,
    };
    $scope.$on('msg2', function(e, msg) {
        $scope.confirm({});
    });

    $scope.tableLoanDatas = {
        "sAjaxSource": "/tenancy-sys/landlord/queryLandlordProcessById",
        "dom": "tr",
        "aoColumns": [
            // {
            //         "mDataProp": "StageStatus",
            //         "sTitle": "阶段",
            //         "sDefaultContent": "",
            //         "sClass": "center landlordStatus",
            //         "sWidth": "120px"
            //     },
            {
                "mDataProp": "checkStatus",
                "sTitle": "操作",
                "sDefaultContent": "",
                "sClass": "center landlordStatus22",
                "sWidth": "120px",
                "mRender": function(data, type, full) {
                    return claimList[data].next;
                }
            }, {
                "mDataProp": "createTime",
                "sTitle": "操作时间",
                "sDefaultContent": "",
                "sClass": "center"
            }, {
                "mDataProp": "inputUser.userName",
                "sTitle": "审核人",
                "sDefaultContent": "",
                "sClass": "center"
            }, {
                "mDataProp": "rejectReason",
                "sTitle": "审核意见",
                "sDefaultContent": "",
                "sClass": "center"
            }, {
                "mDataProp": "checkStatus",
                "sTitle": "目标状态",
                "sDefaultContent": "",
                "sClass": "center landlordStatus11",
                "mRender": function(data, type, full) {
                    return _mlist[data].next;
                }
            }
        ],
        "fnRowCallback": function(nRow, aData, iDisplayIndex) {
            if (aData.checkStatus == "RETURNBACK") {
                var statusStr = "回退补件";
            } else if (aData.checkStatus == "CHECKSUCCESS") {
                var statusStr = "审核通过";
            } else if (aData.checkStatus == "CHECKFAILE") {
                var statusStr = "审核未通过";
            } else if (aData.checkStatus == "INREVIEW") {
                var statusStr = "审核中";
            } else {
                var statusStr = "房东待审核";
            }

            $(nRow).find(".landlordStatus").empty().append(statusStr);

            // $scope.$apply();



        },
        "fnDrawCallback": function(oSettings) {

        },
        "fnServerParams": function(aoData) {
            aoData.push({
                'name': 'queryParams',
                'value': $scope.queryParams,
            });
            return aoData;
        },
        "fnServerData": function(sSource, aData, fnCallback, dataTableObject) {
            //自定义给datatables传递的参数
            var obj = dataTableObject.oAjaxData,
                _baseParams = {
                    'page': obj.iDisplayStart / obj.iDisplayLength + 1,
                    'rows': obj.iDisplayLength,
                    'search': 'false',
                    'nd': '1494221804416',
                    'landlordId': $scope.landlordId1
                };

            var __data = angular.extend({}, _baseParams, obj.queryParams);
            rest.decoJava({
                type: "post",
                url: sSource,
                data: __data,
                beforeSend: function(request) {
                    request.setRequestHeader("token", token);
                },
                success: function(data) {
                    $scope.myDatas = data;
                    if (data.result != null) {
                        var data1 = {
                            'aaData': data.result,
                            'sEcho': obj.sEcho,
                            // 'iTotalDisplayRecords': data.result.page.recordCount,
                            'iTotalRecords': data.records,
                        };
                        fnCallback(data1);
                    } else {
                        return false;
                    }



                }
            });
        }
    };
});